﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>呷饭网</title>
    <link rel="stylesheet" type="text/css" href="./styles/mobile.css" />
    <link href="styles/jquery.ui.all.css" rel="stylesheet" />
    <script type="text/javascript" src="scripts/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="scripts/jquery.bgiframe-2.1.1.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.core.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.widget.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.mouse.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.button.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.draggable.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.position.js"></script>
    <script type="text/javascript" src="scripts/jquery.ui.dialog.js"></script>
    <link href="styles/flexy-menu.css" rel="stylesheet" />
    <script type="text/javascript" src="scripts/flexy-menu.js"></script>
    <script type="text/javascript" src="scripts/common.js"></script>

    <script type="text/javascript">
        var PageFlag;
        $(function () {
            $(".flexy-menu").flexymenu({ speed: 100 });
            getUserInfo();
            getListData("");
            PageFlag = getParameter("PageFlag");
            $('.goback').click(function () {
                if (PageFlag == "1") {
                    window.location.href = "./manager.html";
                }
                else {
                    window.location.href = "./login.html";
                }
            });
        });

        function getListData(flag) {
            getCookList(flag);
        }

        //获取酒店待烹饪数据
        function getCookList(flag) {
            $("#tbllist").html("");

            if (flag == "Urgent") {
                $("#all").removeClass("active");
                $("#general").removeClass("active");
                $("#urgent").addClass("active");
                $("#info").html("待烹调");
            }
            else if (flag == "General") {
                $("#all").removeClass("active");
                $("#urgent").removeClass("active");
                $("#general").addClass("active");
                $("#info").html("烹调中");
            }
            else {
                $("#urgent").removeClass("active");
                $("#general").removeClass("active");
                $("#all").addClass("active");
                $("#info").html("待处理");
            }

            var datas = "&flag=" + flag;
            var url = "CommonPage.aspx?opration=getCookList" + datas;
            $.ajax({
                url: url,
                type: "post",
                dataType: 'json',
                success: function (data) {
                    if (data.Success) {
                        $("#Total").text(data.Total);
                        $(".tips")[0].style.display = "none";
                        //<td class='c'>" + data.List[i].Name + "</td>
                        for (var i = 0, str = ''; i < data.List.length; i++) {
                            if (data.List[i].DishState == 10) {
                                str += "<tr><td class='l'>" + (i + 1) + "</td><td class='c'><input type='checkbox' lang='" + data.List[i].OrderId + "' title='" + data.List[i].DishId + "' value='" + data.List[i].CookbookId + "' name='" + data.List[i].CookingNumber + "' class='checkbox' onclick='ckbox(this);'/></td><td class='l'>" + data.List[i].DishName + "<b>" + data.List[i].Copies + "</b></td><td class='r'><a href='#' onclick='updateCookState2(" + data.List[i].OrderId + "," + data.List[i].DishId + "," + data.List[i].CookbookId + ");'>烹调</a></td></tr>";
                            }
                            else {
                                if (data.List[i].Flag == "0") {
                                    str += "<tr><td class='l'>" + (i + 1) + "</td><td class='c'></td><td class='l'>" + data.List[i].DishName + "<b>" + data.List[i].Copies + "</b></td><td class='cc' style='text-align: left;'>" + data.List[i].CookChef + "</td></tr>";
                                }
                                else {
                                    str += "<tr><td class='l'>" + (i + 1) + "</td><td class='c'></td><td class='l'>" + data.List[i].DishName + "<b>" + data.List[i].Copies + "</b></td><td class='r'><a href='#' onclick=\"updateCookState3('" + data.List[i].DishId + "','" + data.List[i].CookChef + "');\">完成</a></td></tr>";
                                }
                            }
                        }

                        $("#tbllist").html(str);
                    }
                    else {
                        if (data.Url != "") {
                            updateTip(data.Msg, true, "URL", data.Url);
                        }
                        else {
                            $("#Total").text("0");
                            $(".tips")[0].style.display = "";
                            $("#msgtip").text(data.Msg);
                        }
                    }
                }
            });
        }

        function ckbox(o) {
            var count = 0;
            if (o.checked) {
                $(".checkbox").each(function (i, obj) {
                    if (o.value != obj.value) {
                        obj.disabled = true;
                    }
                    if (obj.checked == true) {
                        count++;
                    }
                });

                if (o.name < count) {
                    updateTip("此菜品最多合并数为" + o.name + "份！", false, "", "");
                    o.checked = false;
                }
            }
            else {
                $(".checkbox").each(function (i, obj) {
                    if (obj.checked == true) {
                        count++;
                    }
                });

                $(".checkbox").each(function (i, obj) {
                    if (count == 0) {
                        obj.disabled = false;
                    }
                });
            }
        }

        //菜肴烹调
        function updateCookState2(OrderId, DishId, CookbookId) {
            var arrOrderId = "";
            var arrDishId = "";
            $(".checkbox").each(function (i, obj) {
                if (CookbookId == obj.value && obj.checked == true) {
                    arrOrderId += obj.lang + ",";
                    arrDishId += obj.title + ",";
                }
            });
            
            var datas = "&OrderId=" + OrderId + "&DishId=" + DishId + "&arrOrderId=" + arrOrderId + "&arrDishId=" + arrDishId;
            var url = "CommonPage.aspx?opration=updateCookState2" + datas;
            $.ajax({
                url: url,
                type: "post",
                dataType: 'json',
                success: function (data) {
                    if (data.Success) {
                        //updateTip(data.Msg, true, "Method", "");
                        getListData("");
                    }
                    else {
                        if (data.Url != "") {
                            updateTip(data.Msg, true, "URL", data.Url);
                        }
                        else {
                            updateTip(data.Msg, false, "", "");
                        }
                    }
                }
            });
        }

        //菜肴完成
        function updateCookState3(DishId, CookChef) {
            var datas = "&DishId=" + DishId + "&CookChef=" + encodeURIComponent(CookChef);
            var url = "CommonPage.aspx?opration=updateCookState3" + datas;
            $.ajax({
                url: url,
                type: "post",
                dataType: 'json',
                success: function (data) {
                    if (data.Success) {
                        //updateTip(data.Msg, true, "Method", "");
                        getListData("");
                    }
                    else {
                        if (data.Url != "") {
                            updateTip(data.Msg, true, "URL", data.Url);
                        }
                        else {
                            updateTip(data.Msg, false, "", "");
                        }
                    }
                }
            });
        }
    </script>
</head>

<body>
    <div class="wrapall">
        <table class="topbar">
            <tr>
                <td class="l"><a class="goback">返回</a></td>
                <td class="c" id="H_Name"></td>
                <td class="r" align="right">
                    <ul class="flexy-menu">
                        <li id="lilist">
                        </li>
                    </ul>
                </td>
            </tr>
        </table>
        <p class="textinfo">共有<b id="Total">0</b>菜<label id="info"></label></p>
        <table class="tab1">
            <tr>
                <td class="active" id="all"><a href="#" onclick="getCookList('');">全部</a></td>
                <td id="urgent"><a href="#" onclick="getCookList('Urgent');">待烹调</a></td>
                <td id="general"><a href="#" onclick="getCookList('General');">烹调中</a></td>
            </tr>
        </table>
        <table class="tbllist" id="tbllist">
        </table>
        <span class="tips" style="display: none;"><i></i><b id="msgtip"></b>
            
        </span>
        <br />
    </div>
    <div id="dialog" title="提示信息" style="text-align: center; vertical-align: middle;">
        <p class="dialogTip"></p>
    </div>
</body>
</html>
